<?php namespace App\Http\Controllers;

use App\Answers;
use App\Banner;
use App\Classify;
use App\DakaContent;
use App\Page;
use DB;
use App\Plan;
use App\PlanJoin;
use App\Profession;
use App\Questions;
use App\SysFeedback;
use App\User;
use App\UserInfo;
use App\VisitLog;
use Illuminate\Contracts\Auth\Guard;
use Auth;
use Illuminate\Http\Request;

class MyLifeController extends Controller
{
    public function classifyList(Request $request){
        if(Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $classify = Classify::orderBy('id','desc')->get();

//        echo '<pre>';
//        print_r($classify);
//        die;
        if(count($classify) > 0){
            foreach($classify as $class){
                $class->img_url = route('Api.File.showImageById',['id' => $class->img_id]);
            }
        }

        return view('admin.classify-list',['classify' => $classify]);
    }

    public function contentList(Request $request){
        if(Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $content = DB::connection('mysql_life')->table('content')->orderBy('id','desc')->get();

        if(count($content) > 0){
            foreach($content as $con){
                $classify = DB::connection('mysql_life')->table('classify')->whereId($con->c_id)->first();
                $con->c_title = $classify?$classify->title:'无';
            }
        }

        return view('admin.content-list',['content' => $content]);
    }

    public function contentSet(Request $request){
        if(Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $id = !is_null($request->get('id'))?$request->get('id'):0;

        $sysContent = DB::connection('mysql_life')->table('content')->whereId($id)->first();

        $classify = DB::connection('mysql_life')->table('classify')->orderBy('id','desc')->get();


        return view('admin.content-set',['sysContent' => $sysContent,'classify' => $classify]);

    }

    public function listList(Request $request){
        if(Auth::guard('admin')->guest())
            return redirect(route('Admin.Home.login'));

        $list = DB::connection('mysql_life')->table('list')->orderBy('id','desc')->get();

//        echo '<pre>';
//        print_r($classify);
//        die;
        if(count($list) > 0){
            foreach($list as $li){
                $li->img_url = route('Api.File.showImageById',['id' => $li->img_id]);
            }
        }

        return view('admin.list-list',['list' => $list]);
    }

}